package com.example.controller;

import com.example.service.IndexService;
import com.example.utils.DataChange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

@RestController
public class IndexController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private IndexService indexService;

    /***
     *
     * 客户端请求服务器访问配置
     * @return
     */
    @RequestMapping(value = "{appKey}/{serverKey}/{timeStamp}")
    public void callBack(@PathVariable String appKey, @PathVariable String serverKey, @PathVariable long timeStamp, HttpServletRequest request, HttpServletResponse response) {
        indexService.request(appKey, serverKey, timeStamp, request, response);
    }

    /***
     *
     * 手动刷新配置
     */
    @RequestMapping(value = "setDataChange")
    public String setDataChange() {
        String uuid = UUID.randomUUID().toString();
        DataChange dataChange = new DataChange();
        dataChange.setAppKey("sitc-ekp");
        dataChange.setPropName("sitc.sms.user");
        dataChange.setPropValue(uuid);
        indexService.refresh(dataChange);
        return uuid;
    }

    @RequestMapping(value = "getServer")
    public void getServer() {
        indexService.getServer();
    }
}
